package com.demo.api;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.jfinal.kit.JsonKit;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.weixin.sdk.api.AccessTokenApi;
import com.jfinal.weixin.sdk.api.ApiResult;
import  com.jfinal.kit.*;

public class MsgCustomApi {
	  // 发送客服消息
    private static String customSend = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=";

   
	
	/**
	 * 客服消息
	 */
	public ApiResult createCustom(String jsonStr) {
		String jsonResult = HttpKit.post(customSend + AccessTokenApi.getAccessToken().getAccessToken(), jsonStr);
		return new ApiResult(jsonResult);
	}
	
	/**
	 * 客服数据封装
	 */
	public static String  createCustomJson(String touser,String msgtype,Map map){
        Record article = new Record();
        Record articla = new Record();
        List articleLista = new ArrayList();
        article.set("touser", touser);
        article.set("msgtype", msgtype);

		if (msgtype.equals("news")){
			articleLista.add(map);
			articla.set("articles", articleLista);
	        article.set(msgtype, articla);
		}else {
	        article.set(msgtype, map);
		}
		 String jsonstring = JsonKit.toJson(article);
		System.out.println("getAccessToken().getAccessToken()"+ AccessTokenApi.getAccessToken().getAccessToken());

		 System.out.println("jsonstring======================="+jsonstring);
		return jsonstring;
	}
}
